package com.fengxu.springcloud.controller;

import com.fengxu.springcloud.service.PaymentService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;


@RestController
@Log4j2
public class PaymentController {

    @Autowired
    private PaymentService paymentService;

    @Value("${server.port}")
    private String serverPort;

    @GetMapping("/ok/{id}")
    public String payment_ok(@PathVariable("id") Long id){
        log.info("访问一次ok地址");
       return paymentService.payment_ok(id) + " 端口:" + serverPort;
    }

    @GetMapping("/timeout")
    public String payment_timeout(){
        log.info("访问一次timeout地址");
        return paymentService.payment_timeout() + " 端口:" + serverPort;
    }

    // 这里调用启用了服务熔断的服务
    @GetMapping("/circuit/{id}")
    public String payment_circuit(@PathVariable("id") Long id){
        log.info("访问一次payment_circuit地址");
        return paymentService.paymentCircuitBreaker(id)+ " 端口:" + serverPort;
    }

}
